<template>
  <v-details
    :inputConfig="inputConfig"
    :detailData="inputData"
    :rules="rules"
    @pop="setData"
    ref="input"
  ></v-details>
</template>

<script>
import details from 'commons/Detail'
import baseMixin from "@/mixins/BaseMixin";

export default {
  props: {
    inputData: {
      type: Object,
    }
  },
  mixins: [baseMixin],
  name: "",
  data () {
    //自定义验证规则,验证LPN是否合法
    const inventoryValidate = (rule, value, callback) => {
      let reg = /^\+?[1-9]\d*$/;//
      if (!reg.test(value)) {
        this.$message.error(this.$t('app.inputGreaterZeroNumberPlease'));
        this.inputData.inventory = 1
        callback(new Error())
      } else {
        callback()
      }
    }
    return {
      rules: {
        sku: [
          { required: true, trigger: 'blur', },
        ],
        inventory: [
          { required: true, trigger: 'blur', validator: inventoryValidate },
        ],
        subkey: [
          { required: true, trigger: 'blur', },
        ],
        loc: [
          { required: true, trigger: 'blur', },
        ],
      },
      type: 'pdycwh'
    }
  },
  computed: {
    inputConfig () {
      return [
        [
          {
            type: "table",
            label: this.$t('work.subkey'),
            props: "subkey",
            tableConfig: [
              {
                label: this.$t('work.totalkey'),
                prop: "totalkey",
                input: "input",
              },
              {
                label: this.$t('work.subkey'),
                prop: "subkey",
                input: "input",
              },
              {
                label: this.$t('common.date'),
                prop: "adddate",
                input: "date"
              },
              {
                label: this.$t('common.status'),
                prop: "status",
                input: "select",
                options: this.getOptions("querycodeLkup/LADYCCSTATUS"),
              },
              {
                label: this.$t('common.type'),
                prop: "type",
                input: "select",
                options: this.getOptions("querycodeLkup/LADYCCTYPE")
              },
              {
                label: this.$t('work.isblind'),
                prop: "isblind",
                input: "select",
                options: this.getOptions("querycodeLkup/YESNO")
              },
            ],
            url: `/queryRtx_ccmirroringList/?/${this.type}`,
          },
          {
            type: "table",
            label: this.$t('config.loc'),
            props: "loc",
            tableConfig: [
              {
                label: this.$t('config.loc'),
                prop: "loc",
                input: "input",
              },
              {
                label: this.$t('common.type'),
                prop: "locationtype",
                input: "select",
                options: this.getOptions("querycodeLkup/LOCTYPE")
              },
              {
                label: this.$t('config.area'),
                prop: "putawayzone",
                input: "select",
                options: this.getOptions("queryPutawayzoneDropDown")
              },
              {
                label: this.$t('config.locFlag'),
                prop: "locationflag",
                input: "select",
                options: this.getOptions("querycodeLkup/LOCFLAG")
              },
              {
                label: this.$t('config.locCategory'),
                prop: "locationcategory",
                input: "select",
                options: this.getOptions("querycodeLkup/LOCCATEGRY")
              },
              {
                label: this.$t('config.loseId'),
                prop: "loseid",
                input: "select",
                options: this.getOptions("querycodeLkup/YESNO")
              },
              {
                label: this.$t('in.comminglelot'),
                prop: "comminglelot",
                input: "select",
                options: this.getOptions("querycodeLkup/YESNO")
              },
              {
                label: this.$t('config.commingleSku'),
                prop: "comminglesku",
                input: "select",
                options: this.getOptions("querycodeLkup/YESNO")
              },
              {
                label: this.$t('config.capacity'),
                prop: "cubiccapacity",
                input: "input",
              },
            ],
            url: `/queryLoc/`
          },
          {
            type: "input",
            label: this.$t('in.lpn'),
            props: "pltno",
          }
        ],
        [
          {
            type: "table",
            label: this.$t('config.sku'),
            props: "sku",
            tableConfig: [
              {
                label: this.$t('config.sku'),
                prop: "sku",
                input: "input",
              },
              {
                label: this.$t('common.desc'),
                prop: "descr",
                input: "input",
              },
              {
                label: this.$t('config.shipper'),
                prop: "storerkey",
                input: "input",
              },
              {
                label: this.$t('config.packaging'),
                prop: "packkey",
                input: "input",
              },
              {
                label: this.$t('config.boxGroup'),
                prop: "cartongroupdescr",
                input: "input",
              },
              {
                label: this.$t('config.allocaStrategy'),
                prop: "strategykey",
                input: "input",
              },
              {
                label: this.$t('config.putawayStrategy'),
                prop: "putawaystrategykey",
                input: "input",
              },
              {
                label: this.$t('in.serialnumbe'),
                prop: "serialnumbe",
                input: "select",
                options: this.getOptions("querycodeLkup/YESNO")
              },
              {
                label: this.$t('config.batchValidate'),
                prop: "lottablevalidationkeydescr",
                input: "input",
              },
              {
                label: this.$t('config.area'),
                prop: "putawayzone",
                input: "select",
                options: this.getOptions("queryPutawayzoneDropDown")
              },
            ],
            url: `/querySku/?/${this.$store.state.wms}`
          },
          {
            type: "input",
            label: this.$t('home.inventory'),
            props: "inventory",
          }
        ]
      ]
    }
  },
  methods: {
    setData (data, id, close, listId) {
      if (listId == "0") {
        if (id == "0") {
          this.$set(this.inputData, 'subkey', data.subkey)
        } else if (id == "1") {
          this.$set(this.inputData, 'loc', data.loc)
        }
      } else if (listId == "1") {
        this.$set(this.inputData, 'sku', data.sku)
      }
      close(false);
    }
  },
  mounted () {
  },
  watch: {},
  components: {
    'v-details': details
  }
}
</script>

<style scoped>
</style>
